package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Description:
 * Date: 2025-10-18
 * Time: 18:58
 */
public class BorrowBook implements IOperation{
    public void work(BookList bookList) {
        System.out.println("借阅图书！！！");

        System.out.print("请输入要借阅的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = bookList.getCurrentSize();
        for (int i = 0; i < currentSize; i++) {
            //获得当前图书
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                if(book.getisBorrow() == true){
                    System.out.println("当前图书已被借出！！！");
                    return;
                }else {
                    book.setisBorrow(true);
                    System.out.println("借阅成功！！！");
                    return;
                }
            }
        }
        System.out.println("没有你所要借的书！！！");
    }
}
